<?php if (!defined('U_ADMIN')) {
    exit;
} ?>
</div>
</div>
</div>

<div class="col-md-12 text-center" id="loading_get_div" style="margin-top: 20%!important;">
    <div class="spinner-border text-primary mt-5" role="status" id="loading_status">
        <span class="sr-only">Loading...</span>
    </div>
    <img src="/assets/images/null.png" class="avatar-img" style="width: 100px;" hidden id="loading_status_img">
    <p class="mt-2 h6" id="loading_status_msg">
        数据加载中
    </p>
    <div id="loading_status_button" hidden>
        <button type="button" class="btn btn-primary mr-2 my-2" onclick="location.reload()">刷新页面</button>
        <a type="button" class="btn btn-light" href="/admin/index">返回主页</a>
    </div>
</div>

<div class="modal fade" id="adm_cap" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static"
     data-keyboard="false">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="modal_title">
                    管理员登录信息修改
                </h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label>账号</label>
                        <input type="text" class="form-control" value="<? echo $this->admConf['ADM_USER']; ?>"
                               id="adm_cap_user">
                    </div>
                    <div class="form-group">
                        <label>当前密码</label>
                        <input type="text" class="form-control" placeholder="请输入当前密码" id="adm_cap_pwd">
                    </div>
                    <div class="form-group">
                        <label>新密码</label>
                        <input type="text" class="form-control" placeholder="请设置新密码" id="adm_cap_newpwd">
                    </div>
                    <div class="form-group mb-2">
                        <button type="submit" class="btn btn-primary btn-block" id="adm_cap_submit">确认修改</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</main>
</div>
<script>
    var initAct = 'get', initPg = 1;
    $(function () {
        if (typeof (init) == "function") {
            init(initAct, initPg)
        } else {
            loading_end(true, null)
        }
        $('[data-toggle="tooltip"]')
            .tooltip()
    });
    $("#adm_cap_submit")
        .click(function () {
            var submit_data = {};
            submit_data.user = $("#adm_cap_user")
                .val();
            submit_data.pwd = $("#adm_cap_pwd")
                .val();
            submit_data.newpwd = $("#adm_cap_newpwd")
                .val();
            $("#adm_revise_submit")
                .html('<i class="spinner-ui fe fe-rotate-cw fe-12 mr-2"></i>修改中');
            $("#adm_revise_submit")
                .attr('disabled', true);
            $.ajax({
                cache: false,
                type: "POST",
                url: '/admin/cap',
                data: submit_data,
                dataType: 'json',
                success: function (data) {
                    $("#adm_revise_submit")
                        .html('确认修改');
                    $("#adm_revise_submit")
                        .attr('disabled', false);
                    if (data.code == 200) {
                        cocoMessage.success(data.msg, 2000);
                        location.reload()
                    } else {
                        cocoMessage.error(data.msg, 2000)
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    cocoMessage.error(textStatus, 2000);
                    $("#adm_revise_submit")
                        .html('确认修改');
                    $("#adm_revise_submit")
                        .attr('disabled', false)
                }
            });
            return false
        });

    function loading(s) {
        if (s) {
            $("#loading_get_div")
                .attr("hidden", false);
            $("#loading_status")
                .attr("hidden", false);
            $("#loading_status_img")
                .attr("hidden", s);
            $("#loading_status_msg")
                .html('数据加载中');
            $("#loading_status_button")
                .attr("hidden", s)
        } else {
            loading_end(true)
        }
        return false
    };

    // function initSuccess(e, a = {}) {
    //     if (e.code === 200){
    //         add_list(e.data.list, !0), e.data.pageList && page_list(e.data.pageList, e.data.currentPage, e.data.maxPage), loading(!1))
    //     }else{
    //         cocoMessage.error(e.msg, 2e3)
    //         loading(!1)
    //     }
    // }
    //
    // function initError(e, a = {}) {
    //     if (cocoMessage.error(e, 2e3), $("#div_error")
    //         .attr("hidden", !1), $("#div_container")
    //         .attr("hidden", !0), loading(!1), "pg" == a.k) {
    //         var t = "pre" == a.id ? "&laquo;" : "next" == a.id ? "&raquo;" : a.id;
    //         $("#page_" + a.id)
    //             .html(t), $("#page_" + a.id)
    //             .attr("disabled", !1)
    //     }
    //     "so" == a.k && ($("#so_submit")
    //         .html("搜索"), $("#so_submit")
    //         .attr("disabled", !1))
    // }

    function loading_end(s, text = null, container = false) {
        $("#loading_status")
            .attr("hidden", true);
        if (s) {
            $("#loading_get_div")
                .attr("hidden", true)
        } else {
            $("#loading_status_img")
                .attr("hidden", s);
            $("#loading_status_msg")
                .html(text);
            $("#loading_status_button")
                .attr("hidden", s)
        }
        $("#div_container")
            .attr("hidden", container)
    };
    $("#so_submit")
        .click(function () {
            var submit_data = {};
            submit_data.act = 'get';
            submit_data.so = $("#so")
                .val();
            submit_data.type = $("#so_type")
                .val();
            $("#so_submit")
                .html('<i class="spinner-ui fe fe-rotate-cw fe-12 mr-2"></i>搜索中');
            $("#so_submit")
                .attr('disabled', true);
            $.ajax({
                cache: false,
                type: "POST",
                data: submit_data,
                dataType: 'json',
                success: function (data) {
                    $("#so_submit")
                        .html('搜索');
                    $("#so_submit")
                        .attr('disabled', false);
                    if (data.code == 200) {
                        add_list(data.data.list);
                        page_list(data.data.pageList, data.data.currentPage, data.data.maxPage)
                    } else {
                        cocoMessage.error(data.msg, 2000)
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    cocoMessage.error(textStatus, 2000);
                    $("#so_submit")
                        .html('搜索');
                    $("#so_submit")
                        .attr('disabled', false)
                }
            });
            return false
        });

    function doPage(id, pg) {
        var submit_data = {};
        submit_data.act = 'get';
        submit_data.pg = pg;
        submit_data.so = $("#so")
            .val();
        $("#page_" + id)
            .attr('disabled', true);
        $("#page_" + id)
            .html('<i class="spinner-ui fe fe-rotate-cw fe-12 mr-2"></i>');
        $.ajax({
            cache: false,
            type: "POST",
            data: submit_data,
            dataType: 'json',
            success: function (data) {
                if (data.code == 200) {
                    add_list(data.data.list);
                    page_list(data.data.pageList, data.data.currentPage, data.data.maxPage)
                } else {
                    cocoMessage.error(data.msg, 2000)
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                cocoMessage.error(textStatus, 2000);
                $("#page_" + id)
                    .html(id);
                $("#page_" + id)
                    .attr('disabled', false)
            }
        });
        return false
    };

    function page_list(list, page, max) {
        $("#poge_list_ul")
            .empty();
        if (list.length > 1) {
            $page_pre = '<li class="page-item"><a class="page-link" id="page_pre" href="javascript:doPage(\'pre\',' + (page - 1) + ')">上一页</a></li>';
            $page_next = '<li class="page-item"><a class="page-link" id="page_next" href="javascript:doPage(\'next\',' + ((page + 1 > max) ? page : (page + 1)) + ')">下一页</a></li>';
            $page_data = '';
            for (var i = 0; i < list.length; i++) {
                if (list[i] == page) {
                    $page_data += '<li class="page-item active"><a class="page-link" id="page_' + list[i] + '" href="javascript:doPage(\'' + list[i] + '\',' + list[i] + ')">' + list[i] + '</a></li>'
                } else {
                    $page_data += '<li class="page-item"><a class="page-link" id="page_' + list[i] + '" href="javascript:doPage(\'' + list[i] + '\',' + list[i] + ')">' + list[i] + '</a></li>'
                }
            }
            $("#poge_list_ul")
                .append($page_pre + $page_data + $page_next)
        }
    }
</script>
<script src="/assets/js/coco-message.js"></script>
<script src="/assets/js/app.js" type="text/javascript"></script>
<script src="/assets/js/ue.min.js" type="text/javascript"></script>
</body>
</html>
